<!DOCTYPE html>
<html lang="en">
<head>
    <title>购买保险</title>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <!-- bootstrap-css -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <!-- //bootstrap-css -->
    <!-- Custom CSS -->
    <link href="/css/style.css" rel='stylesheet' type='text/css'/>
    <link href="/css/style-responsive.css" rel="stylesheet"/>
    <!-- font CSS -->
    <!-- font-awesome icons -->
    <link rel="stylesheet" href="/css/font.css" type="text/css"/>
    <link href="/css/font-awesome.css" rel="stylesheet">
    <!-- calendar -->
    <link rel="stylesheet" href="/css/monthly.css">
    <link rel="stylesheet" href="/css/morris.css" type="text/css"/>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.js"></script>
    <script src="/js/morris.js"></script>
    <script src="/js/raphael-min.js"></script>
    <script src="/js/jquery-1.11.0.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <script src="/js/layer/layer.js" charset="utf-8"></script>
    <style type="text/css">
        input[id="i-name"].error, input[id="l-name"].error,input[id="m-name"].error{
            border: 1px solid red;
        }
    </style>
</head>
<body>
<section id="container">
    <section id="main-content">
        <section class="wrapper">
            <div class="form-w3layouts" style="margin-left: -170px">
                <!-- page start-->
                <div class="row">
                    <div class="col-lg-12">
                        <section class="panel">
                            <header class="panel-heading">
                                购买保险
                                <span class="tools pull-right">
                                <a class="fa fa-chevron-down" href="javascript:;"></a>
                                <a class="fa fa-cog" href="javascript:;"></a>
                                <a class="fa fa-times" href="javascript:;"></a>
                             </span>
                            </header>
                            <div class="panel-body" style="width: 800px; margin: 0 auto;">
                                <form class="form-horizontal" id="buyInsuranceForm">
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*客户证件号：</label>
                                        <div class="col-lg-6">
                                            <input type="text" id="i-name" name="idcard" class="form-control">
                                            <span id="cardmsg"></span>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*车牌号：</label><span
                                            id="msgcarid"></span><span id="msg"></span>
                                        <div class="col-lg-6">
                                            <input type="text" id="l-name" name="carid" class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*保险套餐：</label>
                                        <div class="col-lg-6">
                                            <table class="table table-bordered" id="combo">
                                                <tr>
                                                    <td class="info">选择</td>
                                                    <td width="200px" class="success">套餐类型</td>
                                                    <td class="danger">所含保险</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">应付金额：</label>
                                        <div class="col-lg-6">
                                            <input type="text" id="m-name" name="paymoney" class="form-control">
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*支付状态：</label>
                                        <div class="col-lg-6">
                                            <select name="paystate" id="paystate" class="form-control">
                                                <option value="0">未缴费</option>
                                                <option value="1">已缴费</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">*支付方式：</label>
                                        <div class="col-lg-6">
                                            <select name="paymethod" id="paymethod" class="form-control">
                                                <option value="0">未缴费</option>
                                                <option value="1">支付宝</option>
                                                <option value="2">微信</option>
                                                <option value="3">现金</option>
                                                <option value="4">银行卡</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group has-success">
                                        <label class="col-lg-3 control-label">备注：</label>
                                        <div class="col-lg-6">
                                            <textarea class="form-control" id="remark"
                                                      style="width: 480px;height: 100px"></textarea>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-lg-offset-3 col-lg-6">
                                            <button class="btn btn-primary" type="button" id="submitBtn">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </section>
    </section>
</section>
</body>
</html>
<script type="text/javascript" src="/js/jquery.dcjqaccordion.2.7.js"></script>
<script type="text/javascript" src="/js/scripts.js"></script>
<script type="text/javascript" src="/js/jquery.slimscroll.js"></script>
<script type="text/javascript" src="/js/jquery.nicescroll.js"></script>
<script type="text/javascript" src="/js/jquery.scrollTo.js"></script>
<script type="text/javascript">
    ////定义全局变量
    /////获取当前 输入的用户的uuid
    var suId = null;
    /////获取当前输入的 车辆的 uuid
    var caruuid = null;

    /*    $("#f-name").blur(function () {

        });*/
    ////判断该用户是否已经购买过保险
    var getDetailInfo = function () {
        $.ajax({
            url: "/order/getOrderByUserAndCars.do",
            type: 'post',
            dataType: "json",
            data: {
                scardId: $("#f-name").val(),
                licenseNum: $("#l-name").val(),
            },
            success: function (data) {
                /* console.log(data);*/
                if (data.code == 100002) {
                    $("#msg").html("该客户已经为此爱车购买过保险<a href='/order//toGetDetails.do'>点此查看</a>");
                } else if (data.code == 100001) {
                    $("#msg").html("客户还未录入信息，请先<a href='#'>录入客户信息</a>");
                }
            }
        });
    };
    /////获取当前输入的  客户的 uuid
    $("#i-name").keyup(function () {
        $.ajax({
            type: "post",
            dataType: "json",
            url: "/order/getUserByIdCard.do",
            data: {
                idcard: $("#i-name").val()
            },
            success: function (data) {
                /* console.log(data);*/
                if (data.message == "false") {
                    /* $("#cardmsg").html("请先<a href='#'>添加客户信息</a>");*/
                } else {
                    suId = data.message;
                  /*  $("#cardmsg").html("√");*/
                    /*alert(data.message);*/
                }
            }
        });
    });

    ////获取当前输入的 车牌号的uuid
    $("#l-name").keyup(function () {
        $.ajax({
            type: "post",
            dataType: "json",
            url: "/order/getCarsByLicensenum.do",
            data: {
                licensenum: $("#l-name").val()
            },
            success: function (data) {
                console.log(data);
                if (data.message == "false") {
                    /* $("#cardmsg").html("请先<a href='#'>添加车辆信息</a>");*/
                } else {
                    caruuid = data.message;
                   /* $("#cardmsg").html("√");*/
                }
            }
        });
    });
    $.ajax({
        url: "/order/getAllCombo.do",
        dataType: "json",
        type: "post",
        success: function (data) {
            $.each(data, function (index, obj) {
                var newtr = " <tr><td><input type='checkbox' value='" + obj.comuuid + "' class='combotype' name='combo'></td><td width='100px'>" + obj.combname + "</td><td><table class='" + obj.comuuid + " table table-condensed'></table></td></tr>";
                $("#combo").append(newtr);
                $.each(obj.list, function (index, object) {
                    var newtable = "<tr><td>" + object.insurname + "</td></tr>";
                    $("." + obj.comuuid + "").append(newtable);
                })
            })
        }
    });
    var submitInfo = function () {
         if (!check().form()) {
             return;
         }
        $.ajax({
            url: "/order/buyInsurance.do",
            type: "post",
            dataType: "json",
            data: {
                uid: suId,
                caruid: caruuid,
                paystate: $("#paystate").val(),
                paymethod: $("#paymethod").val(),
                comuuid: $("input[type=checkbox]:checked").val(),
                oremark: $("#remark").val(),
                paymoney: $("#m-name").val()
            },
            success: function (data) {
                if (data) {
                    layer.msg("下单成功....", {icon: 6});
                    var index=parent.layer.getFrameIndex(window.name);
                    parent.getOrderPage();
                    parent.layer.close(index);
                    /*window.location.href = "/order/toOrderQuery.do";*/
                } else {
                    layer.msg("下单失败，请重试", {icon: 6});
                }

            }
        });
    };
    $("#submitBtn").click(function () {
        submitInfo();
    });

    function check() {
        return $("#buyInsuranceForm").validate({
            rules: {
                idcard: {
                    required: true
                },
                carid: {
                    required: true
                },
                combo:{
                    required:true
                },
                paymoney:{
                    required:true
                }

            },
            messages: {
                idcard: {
                    required: ""
                },
                carid: {
                    required: ""
                },
                combo:{
                    required:""
                },
                paymoney:{
                    required:""
                }
            }
        });
    };
</script>